import _router from 'koa-router';
import config from 'config';
import assign from 'object-assign';
import _debug from 'debug';
import * as wx_oauth from '../lib/wx_oauth';
import login from '../lib/wx_login';
import client from '../lib/redis';
import * as wx_mplogin from '../lib/wx_mplogin';
import wx_authorize from '../lib/wx_authorize';

const debug = _debug('app:router:');

export default function () {
  const router = _router({
    prefix: '/oauth'
  });

  /**
  * wechat open platform login api
  */
  router.get('/signin', wx_oauth.auth(config.wx_op, login));
  /**
  * wechat web authorize
  */
  router.get('/authorize', wx_oauth.auth(config.wx_mp, wx_authorize));

  /**
  * use wechat web authorize to login
  */
  router.get('/signin_mp/:uuid', wx_oauth.auth(config.wx_mp, wx_mplogin.afterScanCode));
  router.get('/signin_mp/status/:uuid', wx_mplogin.status);
  router.get('/qrcode', wx_mplogin.genQrcode);

  return router;
}
